#!/bin/bash

secho 'HADOOP_HOME=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' >> /etc/profile;
echo 'export PATH=$HADOOP_HOME/bin:$PATH' >> /etc/profile;
cd ~;
mkdir software;cd software;
groupadd hadoop;
useradd -g hadoop hadoop;
mkdir -p /home/hadoop/app/;
wget http://47.114.163.161:8087/hadoop/hadoop-2.6.0-cdh5.7.0.tar.gz;
tar -zxf hadoop-2.6.0-cdh5.7.0.tar.gz -C /home/hadoop/app/;
sed -i '25d' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;

sed -i '24a export JAVA_HOME=/usr/java/jdk1.8.0_212' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;
sed -i '25a export HADOOP_PREFIX=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;

sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '20a <name>fs.defaultFS</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '21a <value>hdfs://hadoop001:9000</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;

sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '20a <name>dfs.replication</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '21a <value>1</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '23a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '24a <name>dfs.namenode.secondary.http-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '25a <value>hadoop001:50090</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '26a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '27a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '28a <name>dfs.namenode.secondary.https-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '29a <value>hadoop001:50091</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '30a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;

sed -i 's/localhost/hadoop001/g' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/slaves;

cp /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml.template /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '20a <name>mapreduce.framework.name</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '21a <value>yarn</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;

sed -i '17a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '18a <name>yarn.nodemanager.aux-services</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '19a <value>mapreduce_shuffle</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '20a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;

/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/bin/hdfs namenode -format >> /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/bin/format.log;

yum -y install expect >> yum.log;
cd /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/sbin;
wget http://47.114.163.161:8087/hadoop/start_hadoop-2.6.0-cdh5.7.0.sh
chmod +x start_hadoop-2.6.0-cdh5.7.0.sh;
/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/sbin/start_hadoop-2.6.0-cdh5.7.0.sh >> hadoop.log;
